from time import time
import ssl
import requests
from urllib.parse import quote, unquote

from pymysql.converters import escape_string
ssl._create_default_https_context = ssl._create_unverified_context()
from Redis import RedisClient
referer = 'https://www.ixueshu.com/q=数据库'

# headers = {
#     "sec-ch-ua-platform": "macOS",
#     "Upgrade-Insecure-Requests": "1",
#     "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36",
#     "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
#     "Sec-Fetch-Site": "same-origin",
#     "Sec-Fetch-Mode": "navigate",
#     "Sec-Fetch-User": "?1",
#     "Sec-Fetch-Dest": "document",
#     "Accept-Encoding": "gzip, deflate, br",
#     "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
# }
# red=RedisClient()
# adsl = red.ADSL()
# proxies = {}
# if adsl:
#     proxies = {
#         'http': 'http://xiaohengheng:950218@' + adsl,
        # 'https': 'http://xiaohengheng:950218@' + adsl,
    # }
# r = requests.get(url, headers=headers, timeout=10, proxies=proxies)
# r = requests.get("https://www.huadiyingyuan.com//v2/1000001912044211/info?jsonpCallback=jQuery18303259121680234245_1636706844167&_=1636706856271",headers=headers,proxies=proxies)
# print(r.content)
headers = {
    "sec-ch-ua-platform": "macOS",
    "Upgrade-Insecure-Requests": "1",
    "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36",
    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
    "Sec-Fetch-Site": "same-origin",
    "Sec-Fetch-Mode": "navigate",
    "Sec-Fetch-User": "?1",
    "Sec-Fetch-Dest": "document",
    "Accept-Encoding": "gzip, deflate, br",
    "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
    "Referer": "https://www.ixueshu.com/",
    "x-dsa-host": "ixueshu.com",
    "x-dsa-originalip": "47.0.0.0",
    "x-dsa-secret": "DSA20130311X"
}
# response = requests.get('https://www.ixueshu.com/search/index.html?search_type=thesis&q=%E6%95%B0%E6%8D%AE',headers=headers)
print(quote(referer, 'utf-8'))
mysql_text = escape_string('')
print(mysql_text)

data = {
    'redirect': '/',
    'username': '17601253218',
    'password': '63505711'
}
r = requests.post('https://www.ixueshu.com/login.html', headers=headers, data=data, verify=False)
save_cookie = {}
cookies = r.cookies._cookies['.ixueshu.com']['/']
for key in cookies.keys():
    save_cookie[cookies[key].name] = cookies[key].value
cookies302 = r.history[0].cookies._cookies['www.ixueshu.com']['/']
for key in cookies302.keys():
    save_cookie[cookies302[key].name] = cookies302[key].value
print(save_cookie)
print(r)